define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'user.order/index',
        add_url: 'user.order/add',
        edit_url: 'user.order/edit',
        delete_url: 'user.order/delete',
        export_url: 'user.order/jsExport',
        modify_url: 'user.order/modify',
    };

    var Controller = {

        index: function () {
            ea.table.render({
                init: init,
                cols: [[
                    {type: 'checkbox'},
                    // {field: 'id', title: 'id'},
                    {field: 'order_sn', title: '订单编号', minWidth: 80},
                    {
                        field: 'pay_type', title: '支付类型', width: 80,
                        selectList: {1: '支付宝', 2: '微信', 3: '银行卡'},
                        templet: function (d) {
                            return d.pay_type_name;
                        }
                    },
                    {field: 'uid', title: '用户id', width: 80},
                    // {field: 'store_id', title: '店铺id'},
                    {field: 'store.title', title: '店铺'},
                    {
                        field: 'total_price', title: '消费金额', templet: function (d) {
                            return '<div style="text-align: left;">' +
                                '订单总金额：<span class="color-red">￥' + d.total_price + '</span>' +
                                '<br/>实支付金额：<span class="color-red">￥' + d.true_price + '</span>' +
                                '<br/>代金券减免：<span class="color-red">￥' + d.cashcard_dec + '</span></div>';
                        }
                    },
                    // {field: 'cashcard_id', title: '代金券id'},
                    // {field: 'cashcard_dec', title: '代金券减免', width: 90},
                    // {field: 'true_price', title: '实际支付', width: 90},
                    // {field: 'refund', title: '退款金额', width: 90},
                    {
                        field: 'create_time', minWidth: 50, title: '订单时间', search: 'range', templet: function (d) {
                            let pay_at = d.pay_at || '未支付';
                            let refund_at = d.refund_time || '未退款';
                            return '<div style="text-align: left;"><span class="">生成：' + d.create_time + '</span>' +
                                '<br/><span class="">支付：' + pay_at + '</span>' +
                                '<br/><span class="">退款：' + refund_at + '</span></div>';
                        }
                    },
                    {
                        field: 'status', title: '订单状态', width: 100,
                        selectList: {'-1': '支付失败', 1: '待支付', 2: '已支付', 3: '退款中', 4: '已退款'},
                        templet: function (d) {
                            return d.status_name;
                        }
                    },
                    {width: 150, title: '操作', templet: ea.table.tool},
                ]],
            });

            ea.listen();
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
    };
    return Controller;
});